package top.lixb.libcommon.base;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.support.multidex.MultiDex;

import com.alibaba.android.arouter.launcher.ARouter;

import com.tencent.bugly.Bugly;

import com.vondear.rxtool.RxTool;

import cn.jpush.android.api.JPushInterface;
import top.lixb.libcommon.BuildConfig;
import top.lixb.libcommon.config.LibConfig;
import top.lixb.libcommon.log.L;

public class BaseApplication extends Application implements Application.ActivityLifecycleCallbacks {

    protected static BaseApplication sApp;


    public Activity getCurActivity() {
        return curActivity;
    }

    protected Activity curActivity;

    @Override
    public void onCreate() {
        super.onCreate();
        sApp = this;
        initARouter();
        initJPush();
        RxTool.init(this);
        Bugly.init(this, LibConfig.Bugly_id, BuildConfig.DEBUG);
        registerActivityLifecycleCallbacks(this);
        L.log_level = BuildConfig.DEBUG ? 10 : -1;

    }



    private void initJPush() {
        if (LibConfig.jpush_enable) {
            JPushInterface.init(this);
            JPushInterface.setDebugMode(BuildConfig.DEBUG);
        }
    }


    private void initARouter() {
        if (BuildConfig.DEBUG) {
            ARouter.openLog();
            ARouter.openDebug();
            ARouter.printStackTrace();
        }
        ARouter.init(this);
    }


    public static BaseApplication getApp() {
        return sApp;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }


    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {
        curActivity = activity;
    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }
}
